package com.cetc.nsfx.service;

import java.io.File;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cetc.nsfx.mapper.IntelligentMapper;

import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.UnderlineStyle;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;

@Service
@Transactional
public class IntelligentService {
	@Autowired
	 private IntelligentMapper intelligentMapper;
	
	/**
     * 获取某个智能提示类别的统计
     * @param param
     * @return
     */
    public List<Map<String,Object>> getIntelligentSourceTotal(Map<String,Object> param){
		return intelligentMapper.getIntelligentSourceTotal(param);
	}
    
    final int defRow = 0;//默认列头行
	int rowNum = 2; //数据开始的行编号
    public void writeExportData(WritableSheet sheet,Map<String,Object> map){
    	try {
    		List<Map<String,Object>> mapList = intelligentMapper.getIntelligentSouceList(map);
    		//定义列头样式
			WritableFont wf_merge0 = new WritableFont(WritableFont.createFont("宋体"),10,WritableFont.BOLD,
	                false,UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK);
			WritableCellFormat wff_merge0 = new WritableCellFormat(wf_merge0);
			wff_merge0.setAlignment(jxl.format.Alignment.CENTRE);
			wff_merge0.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
			wff_merge0.setBorder(Border.ALL, BorderLineStyle.THIN);
			//定义数据行样式
			WritableFont wf_merge1 = new WritableFont(WritableFont.createFont("宋体"),10,WritableFont.NO_BOLD,
	                false,UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK);
			WritableCellFormat wff_merge1 = new WritableCellFormat(wf_merge1);
			wff_merge1.setAlignment(jxl.format.Alignment.CENTRE);
			wff_merge1.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
			wff_merge1.setBorder(Border.ALL, BorderLineStyle.THIN);
			sheet.setRowView(0, 500); //设置第一行行高
			sheet.setRowView(1, 250); //设置第二行行高
			sheet.mergeCells(0, 0, 8, 0);
			//定义标题样式
			WritableFont wf_title = new WritableFont(WritableFont.ARIAL,12,WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK);
			WritableCellFormat wcf_title = new WritableCellFormat(wf_title);
			wcf_title.setBackground(jxl.format.Colour.WHITE);//设置背景色
			wcf_title.setAlignment(jxl.format.Alignment.CENTRE);//左右对齐方式
			wcf_title.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);//上下对齐方式
			wcf_title.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN,jxl.format.Colour.BLACK);
			
			Label label = new Label(0,defRow,"网上办税登录账号",wff_merge0);
			sheet.addCell(label);
			label = new Label(1,defRow,"姓名",wff_merge0);
			sheet.addCell(label);
			label = new Label(2,defRow,"归属地",wff_merge0);
			sheet.addCell(label);
			label = new Label(3,defRow,"手机号码",wff_merge0);
			sheet.addCell(label);
			label = new Label(4,defRow,"指标",wff_merge0);
			sheet.addCell(label);
			label = new Label(5,defRow,"性别",wff_merge0);
			sheet.addCell(label);
			for(Map<String,Object> row : mapList){
				label = new Label(0,rowNum,getString(row.get("WSBSZH")),wff_merge1);
				sheet.addCell(label);
				label = new Label(1,rowNum,getString(row.get("XM")),wff_merge1);
				sheet.addCell(label);
				label = new Label(2,rowNum,getString(row.get("GSD")),wff_merge1);
				sheet.addCell(label);
				label = new Label(3,rowNum,getString(row.get("SJHM")),wff_merge1);
				sheet.addCell(label);

				label = new Label(4,rowNum,getString(row.get("ZBKEY")),wff_merge1);
				sheet.addCell(label);
				label = new Label(5,rowNum,getString(row.get("XB")),wff_merge1);
				sheet.addCell(label);
				rowNum++;
			}
    	}catch(Exception e){
    		e.printStackTrace();
    	}
    }
    
    public String getString(Object obj){
		String result = "";
		if(obj==null){
			
		}else {
			result = obj.toString();
		}
		return result;
	}
}
